
import { login, logOutIns } from "../../services/login"
import { removeCookie } from "../../utils/auth"
import { routerRedux } from 'dva/router';
export default {

  namespace: 'login',

  state: {},

  effects: {
    *loginInfo({ payload }, { call, put }) {
      return yield login(payload)
    },
    
    *logOut({ payload }, { call, put }) {
      yield logOutIns(payload);
      yield removeCookie();
      localStorage.clear();
      yield put(routerRedux.replace('/login'));
    },

    *fetch({ payload }, { call, put }) {  // eslint-disable-line
      yield put({ type: 'save' });
    },
  },

  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
  },

};
